package com.zs.pig.gw.portl.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.zs.pig.blog.api.model.Blog;
import com.zs.pig.blog.api.service.BlogService;
import com.zs.pig.cms.api.model.CmsArticle;
import com.zs.pig.cms.api.model.CmsCategory;
import com.zs.pig.cms.api.model.Product;
import com.zs.pig.cms.api.service.CmsArticleService;
import com.zs.pig.cms.api.service.CmsCategoryService;
import com.zs.pig.cms.api.service.CmsImgService;
import com.zs.pig.cms.api.service.GwInfoService;
import com.zs.pig.cms.api.service.NavService;
import com.zs.pig.cms.api.service.ProductService;
import com.zs.pig.cms.api.service.ProductTypeService;
	/**
	 * 
	 * @author zs 2016-5-5 11:33:51
	 * @Email: 951449465@qq.com
	 * @version 4.0v
	 *	我的blog
	 */
@Controller
@RequestMapping("gw1")
public class Indexgw1Controller {

	
	@Resource
	private CmsArticleService CmsArticleService;
	@Resource
	private CmsCategoryService CmsCategoryService;
	@Resource
	private NavService NavService;
	@Resource
	private CmsImgService CmsImgService;
	@Resource
	private BlogService BlogService;
	@Resource
	private GwInfoService GwInfoService;
	
	@Resource
	private ProductService ProductService;
	@Resource
	private ProductTypeService ProductTypeService;
	
	/**
	 * 请求主页
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/index")
	public ModelAndView index()throws Exception{
		ModelAndView mav=new ModelAndView();
		
		mav.setViewName("gw1/index");
		return mav;
	}
	@RequestMapping("/about")
	public ModelAndView about()throws Exception{
		ModelAndView mav=new ModelAndView();
		
		mav.setViewName("gw1/about");
		return mav;
	}
	@RequestMapping("/index/ajax/bna")
	public String ajaxindex(HttpServletRequest request) {
		try {
			String id = request.getParameter("order");
			if (id != null && !id.equals("")) {
				CmsArticle a=new CmsArticle();
				PageInfo<CmsArticle> artList =null;
				if("reco".equals(id)){
					a.setWeight(1);
					artList = CmsArticleService.selectPage(1, 40, a,"");
				}else if("late".equals(id)){
					artList = CmsArticleService.selectPage(1, 40, a,"createdate desc");
				}else if("hot".equals(id)){
					artList = CmsArticleService.selectPage(1, 40, a,"hits desc");
				}
				
				request.setAttribute("artList", artList.getList());
			}
		} catch (Exception e) {

		}
		return "pc/ajax-index";
	}
	
	@RequestMapping("/indexT")
	public ModelAndView indexT()throws Exception{
		ModelAndView mav=new ModelAndView();
		
		mav.setViewName("pc/indexT");
		return mav;
	}
	
	@RequestMapping("/indexT/ajax/bna")
	public String ajaxindexT(HttpServletRequest request) {
		try {
			String id = request.getParameter("order");
			if (id != null && !id.equals("")) {
				CmsArticle a=new CmsArticle();
				PageInfo<CmsArticle> artList =null;
				if("reco".equals(id)){
					a.setWeight(1);
					artList = CmsArticleService.selectPage(1, 40, a);
				}else if("late".equals(id)){
					artList = CmsArticleService.selectPage(1, 40, a,"createdate desc");
				}else if("hot".equals(id)){
					artList = CmsArticleService.selectPage(1, 40, a,"hits desc");
				}
				
				request.setAttribute("artList", artList.getList());
			}
		} catch (Exception e) {

		}
		return "pc/ajax-indexT";
	}
	/**
	 * 产品详细信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/house/{id}")
	public String house(@PathVariable("id") Long id,
			@RequestParam(value = "pageNum",required=false,defaultValue="1")Integer pageNum,
			@RequestParam(value = "pageSize",required=false,defaultValue="31")Integer pageSize,
			@ModelAttribute CmsArticle CmsArticle, Model model)throws Exception{
		
		CmsCategory CmsCategory=new CmsCategory();
		CmsCategory.setIsshow(1);
		CmsCategory.setParentId(id);
		List<CmsCategory> cateList=CmsCategoryService.select(CmsCategory);
		model.addAttribute("cateList",cateList);
//		if(cateList!=null && cateList.size()>0){
//			CmsArticle.setCategoryId(cateList.get(0).getId());
//		}
//		PageInfo<CmsArticle> artList=CmsArticleService.selectPage(pageNum, pageSize, CmsArticle);
//		model.addAttribute("page", artList);
		
		return "pc/house";
	}
	
	 @RequestMapping("news")
	  public ModelAndView news() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/news");
	            PageInfo<Blog> page1 = BlogService.selectPage(1, 100, null);
	    		model.addObject("infos", page1.getList());	
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  
	  /**
	   * 新闻详情
	   * @return
	   */
	  @RequestMapping("news-inform/{id}")
	  public ModelAndView newsinform(@PathVariable("id") Long id) {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/news-inform");
	            model.addObject("info", BlogService.selectByPrimaryKey(id));
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  @RequestMapping("about-us")
	  public ModelAndView aboutUs() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/about-us");

	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  /**
	   * 案例详情
	   */
	  @RequestMapping("case-inform/{id}")
	  public ModelAndView caseinform(@PathVariable("id") Long id) {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/case-inform");
	            model.addObject("prj", ProductService.selectByPrimaryKey(id));
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  /**
	   * 客户案例
	   * @return
	   */
	  @RequestMapping("customer-case")
	  public ModelAndView customercase() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/customer-case");
	            PageInfo<Product> page = ProductService.selectPage(1, 9, null);
	    		model.addObject("productList", page.getList());
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  
	  /**
	   * 产品展示
	   * @return
	   */
	  @RequestMapping("product-show")
	  public ModelAndView productshow() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/product-show");
	            PageInfo<Product> page = ProductService.selectPage(1, 9, null);
	    		model.addObject("productList", page.getList());
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  
	  /**
	   * 招贤納试
	   * @return
	   */
	  @RequestMapping("recruit")
	  public ModelAndView recruit() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/recruit");

	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 } 
	  
	  /**
	   * 服务展示
	   * @return
	   */
	  @RequestMapping("service-center")
	  public ModelAndView servicecenter() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/service-center");
	            PageInfo<Blog> page1 = BlogService.selectPage(1, 100, null);
	    		model.addObject("infos", page1.getList());	
	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  
	  /**
	   * 解决方案
	   * @return
	   */
	  @RequestMapping("solutions")
	  public ModelAndView solutions() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/solutions");

	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 }
	  
	  /**
	   * 解决方案详情
	   * @return
	   */
	  @RequestMapping("solutions-inform")
	  public ModelAndView solutionsinform() {
		 try {
	            ModelAndView model = new ModelAndView("/gw1/solutions-inform");

	            return model;
	        } catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException("导航失败!");
	        }
	 } 
}
